﻿<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="MonkeyWarranty.Web._Default" %>

<%@ Import Namespace="MonkeyWarranty.Web.Common" %>
<%@ Import Namespace="Resources" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <title><%= GlobalStrings.Warranty %> - Dashboard</title>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div class="row">
        <div class="col-lg-12">
            <h3>Dashboard</h3>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <% if (WarrantyCommon.HasRole("Admin_DichVu"))
       { %>
    <div class="row">
        <div class="col-lg-3 col-md-6">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <div class="row">
                        <div class="col-xs-3">
                            <i class="fa fa-wrench fa-5x"></i>
                        </div>
                        <div class="col-xs-9 text-right">
                            <div class="huge" id="NewCount">0</div>
                            <div>Bảo hành mới!</div>
                        </div>
                    </div>
                </div>
                <a href="WarrantyTickets/List.aspx?status=1">
                    <div class="panel-footer">
                        <span class="pull-left">Xem chi tiết</span>
                        <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                        <div class="clearfix"></div>
                    </div>
                </a>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="panel panel-green">
                <div class="panel-heading">
                    <div class="row">
                        <div class="col-xs-3">
                            <i class="fa fa-tasks fa-5x"></i>
                        </div>
                        <div class="col-xs-9 text-right">
                            <div class="huge" id="ProcessingCount">0</div>
                            <div>BH đang xử lý</div>
                        </div>
                    </div>
                </div>
                <a href="WarrantyTickets/List.aspx?status=2">
                    <div class="panel-footer">
                        <span class="pull-left">Xem chi tiết</span>
                        <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                        <div class="clearfix"></div>
                    </div>
                </a>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="panel panel-yellow">
                <div class="panel-heading">
                    <div class="row">
                        <div class="col-xs-3">
                            <i class="fa fa-shopping-cart fa-5x"></i>
                        </div>
                        <div class="col-xs-9 text-right">
                            <div class="huge" id="ProcessingProductsCount">0</div>
                            <div>Hàng đang bảo hành</div>
                        </div>
                    </div>
                </div>
                <a href="WarrantyTickets/ProcessWarranty.aspx">
                    <div class="panel-footer">
                        <span class="pull-left">Xem chi tiết</span>
                        <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                        <div class="clearfix"></div>
                    </div>
                </a>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="panel panel-red">
                <div class="panel-heading">
                    <div class="row">
                        <div class="col-xs-3">
                            <i class="fa fa-support fa-5x"></i>
                        </div>
                        <div class="col-xs-9 text-right">
                            <div class="huge" id="ReceivedProductsCount">0</div>
                            <div>Hàng đang chờ trả</div>
                        </div>
                    </div>
                </div>
                <a href="WarrantyTickets/ReceivedProducts.aspx">
                    <div class="panel-footer">
                        <span class="pull-left">Xem chi tiết</span>
                        <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                        <div class="clearfix"></div>
                    </div>
                </a>
            </div>
        </div>
    </div>
    
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-support fa-fw"></i><%=GlobalStrings.WarrantyTickets%>
                </div>
                <div class="panel-body">
                    <div id="WarrantyTicketsTableContainer"></div>
                </div>
            </div>
        </div>
    </div>
    <% } %>
    
    <% if (WarrantyCommon.HasRole("Admin") || WarrantyCommon.HasRole("Admin_DichVu"))
       { %>

    <% } %>

    <% if (WarrantyCommon.HasRole("Kythuat_DichVu") || WarrantyCommon.HasRole("Admin_DichVu"))
       { %>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-support fa-fw"></i><%=GlobalStrings.InstantTickets%>
                </div>
                <div class="panel-body">
                    <div id="InstantServicesTableContainer"></div>
                    <p></p>
                    <div id="InstantProductsTableContainer"></div>
                </div>
            </div>
        </div>
    </div>
    <% } %>
    
    <% if (WarrantyCommon.HasRole("Kythuat_BaoHanh"))
       { %>

    <% } %>

    <%--<div class="row">
        <div class="col-lg-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-bar-chart-o fa-fw"></i><%=GlobalStrings.InstantTickets%>
                </div>
                <div class="panel-body">
                    <p>
                        <a href="InstantTickets/List.aspx#tabs-1"><%=GlobalStrings.Received %>(<%=NewTicketCount %>)</a>
                    </p>
                    <p>
                        <a href="InstantTickets/List.aspx#tabs-2"><%=GlobalStrings.Processing %>(<%=ProcessingTicketCount %>)</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-bar-chart-o fa-fw"></i><%=GlobalStrings.InstantTickets%>: <%=DateTime.Today.ToString("MM/yyyy") %>
                </div>
                <div class="panel-body">
                    <asp:Repeater ID="rptTicketEmployeeCounts" runat="server" DataSourceID="">
                        <ItemTemplate>
                            <p>
                                <%#DataBinder.Eval(Container.DataItem, "Name") %>: <%#DataBinder.Eval(Container.DataItem, "TicketCount") %>
                            </p>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
            </div>
        </div>
    </div>--%>

    <script type="text/javascript">
        $(function () {
            $("#menu-dashboard").addClass("active");
            LoadStatistic();
            LoadWarrantyTickets();
            LoadInstantServices();
            LoadInstantProducts();
        });
    </script>
    
    <script type="text/javascript">
        function LoadStatistic() {
            $.ajax({
                url: "Default.aspx/Statistic",
                type: "POST",
                contentType: "application/json",
                success: function (data) {
                    $("#NewCount").text(data.d.NewCount);
                    $("#ProcessingCount").text(data.d.ProcessingCount);
                    $("#ProcessingProductsCount").text(data.d.ProcessingProductsCount);
                    $("#ReceivedProductsCount").text(data.d.ReceivedProductsCount);
                }
            });
        }
    </script>
    
    <script type="text/javascript">
        function LoadInstantServices() {
            $('#InstantServicesTableContainer').jtable({
                paging: false,
                sorting: false,
                actions: {
                    listAction: 'Default.aspx/TicketServiceList'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    ServiceName: {
                        title: '<%=GlobalStrings.Services %>',
                        display: function(data) {
                            return '<a title="Cập nhật" href="EmployeePages/InstantTickets/EditService.aspx?id=' + data.record.Id + '">' + data.record.ServiceName + '</a>';
                        }
                    },
                    <%--ServiceTypeName: {
                        title: '<%=GlobalStrings.ServiceType %>'
                    },--%>
                    ErrorName: {
                        title: '<%=GlobalStrings.ErrorCode %>'
                    },
                    CustomerName: {title: '<%=GlobalStrings.Customers %>'},
                    StartDateString: {title: '<%=GlobalStrings.StartDate %>'},
                    EndDateString: {title: '<%=GlobalStrings.EndDate %>'},
                    InstantServiceStatusName: {title: '<%=GlobalStrings.Status %>'}
                    //,Edit: {
                    //    title: '',
                    //    width: '1%',
                    //    sorting: false,
                    //    display: function (data) {
                    //        return '<a title="Cập nhật" href="EditService.aspx?id=' + data.record.Id + '"><i class="fa fa-2x fa-edit"></i></a>';
                    //    }
                    //}
                }
            });

            $('#InstantServicesTableContainer').jtable('load');
        }

        function LoadInstantProducts() {
            $('#InstantProductsTableContainer').jtable({
                paging: false,
                sorting: false,
                actions: {
                    listAction: 'Default.aspx/TicketProductList'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    ProductName: {
                        title: '<%=GlobalStrings.ProductName %>',
                        display: function (data) {
                            return '<a title="Cập nhật" href="EmployeePages/InstantTickets/EditProduct.aspx?id=' + data.record.Id + '">' + data.record.ProductName + '</a>';
                        }
                    },
                    ErrorName: {
                        title: '<%=GlobalStrings.ErrorCode %>'
                    },
                    CustomerName: { title: '<%=GlobalStrings.Customers %>' },
                    StartDateString: { title: '<%=GlobalStrings.StartDate %>' },
                    EndDateString: { title: '<%=GlobalStrings.EndDate %>' },
                    InstantProductStatusName: { title: '<%=GlobalStrings.Status %>' }
                }
            });

            $('#InstantProductsTableContainer').jtable('load');
        }
    </script>

    <script type="text/javascript">
        function LoadWarrantyTickets() {
            $('#WarrantyTicketsTableContainer').jtable({
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'DeliveryDate ASC',
                actions: {
                    listAction: 'Default.aspx/TicketListByFilter'
                },
                fields: {
                    Indicator: {
                        title: '', sorting: false, width: '1%',
                        display: function (data) {
                            return '<img width="20" src="Content/' + data.record.Indicator + '.png" />';
                        }
                    },
                    <%--DaysLeft: {
                        title: '<%= GlobalStrings.DaysLeft %>', sorting: false, width: '1%', display: function (data) {
                            if (data.record.DaysLeft == 0) return '0';
                            return data.record.DaysLeft;
                        }
                    },--%>
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    TicketContent: {
                        title: '<%= GlobalStrings.Content %>', sorting: false,
                        display: function (data) {
                            return '<a href="WarrantyTickets/Edit.aspx?id=' + data.record.Id + '">' + data.record.TicketContent + '</a>';
                        }
                    },
                    CustomerName: { title: '<%= GlobalStrings.Customers %>', width: '4%' },
                    CreatedDate: {
                        title: '<%= GlobalStrings.ReceivedDate %>',
                        type: 'date',
                        displayFormat: 'dd/mm/yy',
                        width: '1%'
                    },
                    DeliveryDate: {
                        title: '<%= GlobalStrings.WishDate %>',
                        type: 'date',
                        displayFormat: 'dd/mm/yy',
                        width: '2%'
                    },
                    //CreatedEmployeeName: { title: '<%= GlobalStrings.ReceivedEmployee %>' },
                    //ReceivedFromName: { title: '<%= GlobalStrings.ReceivedFrom %>' },
                    //DealerEmployeeName: { title: '<%= GlobalStrings.DealerEmployeeName %>' },
                }
            });

            $('#WarrantyTicketsTableContainer').jtable('load');

            setInterval(function () {
                $('#WarrantyTicketsTableContainer').jtable('load');
            }, 300000);
        }
    </script>
</asp:Content>
